# = test.editprofile.5.rb -Profile SiteOptions Test
# See LICENSE.txt for licensing details.
#
# == Description
#To test the functionality for profile Site Options

require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
    
	class TC_ProfileSiteOptions_test < Test::Unit::TestCase
    
    def startup      
      @@ie = Watir::IE.start($SITE_URL)
	  end
	
	  def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
	  end
    
    def test_01_verifyHomeText
      assert(ie.contains_text(/Community Server/))		
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
    
    def test_06_navigateToProfile
      ie.link(:text, 'Edit Profile').click      
    end
    
    def test_07_verifyLinksOnProfilePage
      assert(ie.link(:text, 'admin').exists?)
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Inbox').exists?)
      assert(ie.button(:id, /TitleBarSearchButton$/).exists?)
      assert(ie.link(:text, 'Home').exists?)
      assert(ie.link(:text, 'Blogs').exists?)
      assert(ie.link(:text, 'Forums').exists?)
      assert(ie.link(:text, 'Photos').exists?)
      assert(ie.link(:text, 'Downloads').exists?)
      assert(ie.link(:text, 'Control Panel').exists?)
      assert(ie.link(:text, 'Change Password').exists?)
    end
    
    def test_08_verifyDropDownListsOnProfilePage
      assert(ie.select_list(:id, /Language$/).exists?)
      assert(ie.select_list(:id, /SortOrder$/).exists?)
      assert(ie.select_list(:id, /Theme$/).exists?)
      assert(ie.select_list(:id, /FontSize$/).exists?)
      assert(ie.select_list(:id, /EditorList$/).exists?)
      assert(ie.select_list(:id, /PostViewType$/).exists?)
      assert(ie.select_list(:id, /PageSize$/).exists?)
      assert(ie.select_list(:id, /ControlPanelManageView$/).exists?)
      assert(ie.select_list(:id, /Timezone$/).exists?)
      assert(ie.select_list(:id, /DateFormat$/).exists?)
    end
    
    def test_09_verifyRadioButtonsOnProfilePage
      assert(ie.radio(:id, /EnableBirthday$/).exists?)
      assert(ie.radio(:id, /DisableBirthday$/).exists?)
      assert(ie.radio(:id, /ReceiveEmails_Yes$/).exists?)
      assert(ie.radio(:id, /ReceiveEmails_No$/).exists?)
      assert(ie.radio(:id, /EnableHtmlEmail_Yes$/).exists?)
      assert(ie.radio(:id, /EnableHtmlEmail_No$/).exists?)
      assert(ie.radio(:id, /EnableEmailTracking_Yes$/).exists?)
      assert(ie.radio(:id, /EnableEmailTracking_No$/).exists?)
      assert(ie.radio(:id, /DisplayInMemberList_Yes$/).exists?)
      assert(ie.radio(:id, /DisplayInMemberList_No$/).exists?)
      assert(ie.radio(:id, /EnablePostPreviewPopup_Yes$/).exists?)
      assert(ie.radio(:id, /EnablePostPreviewPopup_No$/).exists?)
      assert(ie.radio(:id, /EnableCollapsingPanels_Yes$/).exists?)
      assert(ie.radio(:id, /EnableCollapsingPanels_No$/).exists?)
      assert(ie.radio(:id, /EnableEmoticons_Yes$/).exists?)
      assert(ie.radio(:id, /EnableEmoticons_No$/).exists?)
      assert(ie.radio(:id, /enableUserAvtars_Yes$/).exists?)
      assert(ie.radio(:id, /enableUserAvtars_No$/).exists?)
      assert(ie.radio(:id, /enableUserSignatures_Yes$/).exists?)
      assert(ie.radio(:id, /enableUserSignatures_No$/).exists?)
      assert(ie.radio(:id, /EnableHelp_Yes$/).exists?)
      assert(ie.radio(:id, /EnableHelp_No$/).exists?)
    end
    
    def test_10_verifyFieldsOnProfilePage
      assert(ie.text_field(:id, /CommonName$/).exists?)
      assert(ie.text_field(:id, /Location$/).exists?)
      assert(ie.text_field(:id, /Occupation$/).exists?)
      assert(ie.text_field(:id, /Interests$/).exists?)
      assert(ie.text_field(:id, /WebAddress$/).exists?)
      assert(ie.text_field(:id, /WebLog$/).exists?)
      assert(ie.text_field(:id, /WebGallery$/).exists?)
      assert(ie.text_field(:id, /PublicEmail$/).exists?)
      assert(ie.text_field(:id, /MsnIM$/).exists?)
      assert(ie.text_field(:id, /AolIM$/).exists?)
      assert(ie.text_field(:id, /YahooIM$/).exists?)
      assert(ie.text_field(:id, /ICQ$/).exists?)
      assert(ie.text_field(:id, /PrivateEmail$/).exists?)
    end
    
    def test_11_verifyCheckBoxesOnProfilePage
      assert(ie.checkbox(:id, /ShareFavoriteUsers$/).exists?)
      assert(ie.checkbox(:id, /ShareFavoritePosts$/).exists?)
      assert(ie.checkbox(:id, /ShareFavoriteSections$/).exists?)
    end
    
    def test_12_verifyButtonsOnProfilePage
      assert(ie.button(:id, /DeleteFavoriteUsers$/).exists?)
      assert(ie.button(:id, /DeleteFavoritePosts$/).exists?)
      assert(ie.button(:id, /DeleteFavoriteSections$/).exists?)
      assert(ie.link(:id, /UpdateButtonBottom$/).exists?)
    end
    
    def test_13_enableRadioButtons
      ie.div(:text, 'Site Options').click
      
      ie.radio(:id, /DisplayInMemberList_Yes$/).set
      ie.radio(:id, /EnableHtmlEmail_Yes$/).set
      ie.radio(:id, /EnableCollapsingPanels_Yes$/).set
      ie.radio(:id, /enableUserSignatures_Yes$/).set
      ie.radio(:id, /EnableHelp_Yes$/).set
       
      ie.link(:id, /UpdateButtonBottom$/).click
      
      assert(ie.contains_text("Your profile has been updated"))
      
      assert(ie.radio(:id, /DisplayInMemberList_Yes$/).isSet?)
      assert(ie.radio(:id, /EnableHtmlEmail_Yes$/).isSet?)
      assert(ie.radio(:id, /EnableCollapsingPanels_Yes$/).isSet?)
      assert(ie.radio(:id, /enableUserSignatures_Yes$/).isSet?)
      assert(ie.radio(:id, /EnableHelp_Yes$/).isSet?)
    end
    
    def test_99_closeIE
      ie.close
    end
    
  end